<template>
      <div>
        <el-radio-group v-model="type" @change="showChart">
            <el-radio-button label="商品销售统计图"></el-radio-button>
            <el-radio-button label="服务统计图"></el-radio-button>
        </el-radio-group>
        <div class="total" id="myChart" ref="myChart"></div>
      </div>
    
</template>
<script>
import echarts from "echarts/lib/echarts";
// 引入饼状图
import "echarts/lib/chart/pie";
// 引入提示框和标题组件
import "echarts/lib/component/tooltip";
import "echarts/lib/component/title";
import "echarts/lib/component/legend";

// import axios from "axios";
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";

// import BMap from 'BMap'
export default {
    data() {
        return {
            type: "商品销售统计图",
            ageAxisData:["北京","上海","广州","深圳","成都","重庆"],
            ageSeriesData:[{"name":"北京","value":3566},{"name":"上海","value":4500},{"name":"广州","value":3900},{"name":"深圳","value":3006},{"name":"成都","value":2900},{"name":"重庆","value":3123}],
            serveData:[{"name":"北京","value":1066},{"name":"上海","value":1233},{"name":"广州","value":1900},{"name":"深圳","value":3909},{"name":"成都","value":2300},{"name":"重庆","value":3123}],
        };
    },
    mounted() {
        this.$nextTick(() => {
            this.showChart();
        });
    },

    methods: {
         showChart() {
            // 销毁之前的实例
            echarts.dispose(this.$refs.myChart);
            // 重新创建新的实例
            let myChart = echarts.init(this.$refs.myChart);
            
            if (this.type == "服务统计图") {         
                let data =this.serveData;
                myChart.setOption(this.serveOpitons, true);
            }else if(this.type == "商品销售统计图"){
                 let data =this.ageSeriesData;
                  myChart.setOption(this.ageOpitons, true);
            }
            
        },
    },
    computed: {
        ageOpitons() {
            return {
                title: {
                    text: "各地区商品销售额分布图",
                    subtext: "纯属虚构",
                    x: "center"
                },
                tooltip: {
                    trigger: "item",
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: "vertical",
                    left: "left",
                    data: this.ageAxisData
                },
                series: [
                    {
                        name: "访问来源",
                        type: "pie",
                        radius: "55%",
                        center: ["50%", "60%"],
                        data: this.ageSeriesData,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: "rgba(0, 0, 0, 0.5)"
                            }
                        }
                    }
                ]
            };
        },
         serveOpitons() {
            return {
                title: {
                    text: "各地区服务分布图",
                    subtext: "纯属虚构",
                    x: "center"
                },
                tooltip: {
                    trigger: "item",
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: "vertical",
                    left: "left",
                    data: this.serveData
                },
                series: [
                    {
                        name: "访问来源",
                        type: "pie",
                        radius: "55%",
                        center: ["50%", "60%"],
                        data: this.serveData,
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: "rgba(0, 0, 0, 0.5)"
                            }
                        }
                    }
                ]
            };
        },
        
    }
};
</script>
<style scoped>
.total {
    width: 100%;
    height: 500px;
}
</style>

